﻿using System.Collections.Generic;
using System.ServiceModel;
using Tierless.Framework.Data;
using Tierless.Framework.EntityTypes;
using Tierless.Framework.ServiceContracts;

namespace Tierless.Framework.Client
{
	public class EntityClient : ClientBase<IAsyncEntityService>, IEntityService
	{
		[System.Diagnostics.DebuggerStepThrough]
		public List<EntitySet> Get(EntityRequests lookupRequest)
		{
			var result = base.Channel.BeginGet(lookupRequest, null, null);
			result.AsyncWaitHandle.WaitOne();
			return base.Channel.EndGet(result);
		}

		[System.Diagnostics.DebuggerStepThrough]
		public EntitySaveResult Save(List<EntitySet> entitySets)
		{
			var result = base.Channel.BeginSave(entitySets, null, null);
			result.AsyncWaitHandle.WaitOne();
			return base.Channel.EndSave(result);
		}

		[System.Diagnostics.DebuggerStepThrough]
		public EntityType[] Describe(string[] entityNames)
		{
			var result = base.Channel.BeginDescribe(entityNames, null, null);
			result.AsyncWaitHandle.WaitOne();
			return base.Channel.EndDescribe(result);
		}
	}
}
